<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
//Includes
use_unit("components4phpfull/jtjavascript.inc.php");
use_unit("components4phpfull/jtgroupbox.inc.php");
use_unit("components4phpfull/jtsitetheme.inc.php");
use_unit("components4phpfull/jtdivwindow.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class Replace_Engine extends Page
{
       public $JTJavaScript4 = null;
       public $JTJavaScript3 = null;
       public $JTJavaScript2 = null;
       public $JTJavaScript1 = null;
       public $btnDelFuel = null;
       public $listFuel = null;
       public $btnAddFuel = null;
       public $edFuel = null;
       public $JTGroupBox1 = null;
       public $JTDivFuel = null;
       public $JTSiteTheme1 = null;
       public $compid = null;
       public $hiddenId = null;
       public $btnEReplace = null;
       public $btnECancel = null;
       public $Label91 = null;
       public $repEngCylinder = null;
       public $btnrepFuel = null;
       public $repEngFuel = null;
       public $Label92 = null;
       public $repEngAspiration = null;
       public $repEngAircon = null;
       public $repEngDisp = null;
       public $Label88 = null;
       public $Label89 = null;
       public $Label90 = null;
       public $repEngTorque = null;
       public $Label87 = null;
       public $repEngPower = null;
       public $Label86 = null;
       public $repEngCode = null;
       public $Label85 = null;
       public $repEngNum = null;
       public $Label93 = null;
       public $Image1 = null;
       function repEngFuelJSChange($sender, $params)
       {

       ?>
       //Add your javascript code here
       window.opener.document.getElementById('cmbfuel').selectedIndex = document.getElementById('repEngFuel').selectedIndex;
       <?php

       }


       function btnDelFuelJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       var FuelIndex = document.getElementById('listFuel').selectedIndex;
       var FuelValue = document.getElementById('listFuel')[FuelIndex].value;
       var comp = document.getElementById('compid').value;
       AjaxFuel3(FuelValue,comp);
       <?php

       }

       function btnAddFuelJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       var addfuel = document.getElementById('edFuel').value;
       var compider = document.getElementById('compid').value;
       AjaxFuel2(addfuel,compider);
       document.getElementById('edFuel').value = "";

       <?php

       }



       function btnrepFuelJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.getElementById('JTDivFuel').Show();
       document.getElementById('edFuel').value = "";
       <?php

       }

       function btnECancelJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       window.close();
       <?php

       }

       function Replace_EngineCreate($sender, $params)
       {
       $this->compid->Value = $_SESSION['company_id'];
       $veh_id = $_GET['veh_id'];

       if($veh_id!='' || $veh_id!=null)
       $this->hiddenId->setValue($veh_id);

       $this->repEngNum->Text = '';
       $this->repEngCode->Text = '';
       $this->repEngPower->Text = '';
       $this->repEngTorque->Text = '';
       $this->repEngDisp->Text = '';
       $this->repEngAircon->Text = '';
       $this->repEngAspiration->Text = '';
       $this->repEngCylinder->Text = '';


       $this->repEngFuel->Clear();
       $result_fuel = mysql_query("select * from lookup_fuel_tbl where company_id = '".$_SESSION['company_id']."' AND category='octane/Types'");

       while($row_fuel = mysql_fetch_array($result_fuel))
       {
        $this->repEngFuel->AddItem($row_fuel['value'], null, $row_fuel['id']);
       }

       $this->listFuel->Clear();
       $result_f = mysql_query("select * from lookup_fuel_tbl where company_id = '".$_SESSION['company_id']."' AND category='octane/Types'");

       while($row_f = mysql_fetch_array($result_f))
       {
        $this->listFuel->AddItem($row_f['value'], null, $row_f['id']);
       }

       }

       function btnEReplaceClick($sender, $params)
       {
       $result = mysql_query("insert into engine_history_tbl (comp_id,
       veh_id,
       eng_num,
       code,
       power,
       torque,
       disp,
       aircon,
       aspiration,
       cylinder,
       fuel_type)

       values ('".$_SESSION['company_id']."',
       '".$this->hiddenId->getValue()."',
       '".$this->repEngNum->Text."',
       '".$this->repEngCode->Text."',
       '".$this->repEngPower->Text."',
       '".$this->repEngTorque->Text."',
       '".$this->repEngDisp->Text."',
       '".$this->repEngAircon->Text."',
       '".$this->repEngAspiration->Text."',
       '".$this->repEngCylinder->Text."',
       '".$this->repEngFuel->getItemIndex()."')")or die("INSERT ENG HISTORY - " . mysql_error());


       mysql_query("update veh_engine_tbl set
       code = '" . $this->repEngCode->Text . "',
       serial_num = '" . $this->repEngNum->Text . "',
       disp_ci = '" . $this->repEngDisp->Text . "',
       aircon_type = '" . $this->repEngAircon->Text . "',
       cylinder = '" . $this->repEngCylinder->Text . "',
       power_bhp = '" . $this->repEngPower->Text . "',
       torque_lb = '" . $this->repEngTorque->Text . "',
       fuel_type = '" . $this->repEngFuel->getItemIndex() . "',
       aspiration = '" . $this->repEngAspiration->Text . "'
       where vehicle_id='" . $this->hiddenId->getValue() . "'")or die("UPDATE ENGINE - " . mysql_error());

       mysql_query("update vehicle_tbl set
       engine_model = '" . $this->repEngNum->Text . "'
       where vehicle_id='" . $this->hiddenId->getValue() . "'")or die("UPDATE ENGINE - " . mysql_error());



       echo "<script type=text/javascript>
        alert('Engine Replaced!');
        window.close();
        </script>";


       }

       function repEngCylinderJSKeyUp($sender, $params)
       {

       ?>
       //Add your javascript code here
       window.opener.document.getElementById('edcylinder').value = document.getElementById('repEngCylinder').value;
       <?php

       }

       function repEngAspirationJSKeyUp($sender, $params)
       {

       ?>
       //Add your javascript code here
       window.opener.document.getElementById('edaspiration').value = document.getElementById('repEngAspiration').value;
       <?php

       }

       function repEngAirconJSKeyUp($sender, $params)
       {

       ?>
       //Add your javascript code here
       window.opener.document.getElementById('edAircon').value = document.getElementById('repEngAircon').value;
       <?php

       }

       function repEngDispJSKeyUp($sender, $params)
       {

       ?>
       //Add your javascript code here
       window.opener.document.getElementById('eddisp').value = document.getElementById('repEngDisp').value;
       <?php

       }

       function repEngTorqueJSKeyUp($sender, $params)
       {

       ?>
       //Add your javascript code here
       window.opener.document.getElementById('edtorque').value = document.getElementById('repEngTorque').value;
       <?php

       }

       function repEngPowerJSKeyUp($sender, $params)
       {

       ?>
       //Add your javascript code here
       window.opener.document.getElementById('edpower').value = document.getElementById('repEngPower').value;
       <?php

       }

       function repEngCodeJSKeyUp($sender, $params)
       {

       ?>
       //Add your javascript code here
       window.opener.document.getElementById('edcode').value = document.getElementById('repEngCode').value;
       <?php

       }

       function repEngNumJSKeyUp($sender, $params)
       {

       ?>
       //Add your javascript code here
       window.opener.document.getElementById('edserialnum').value = document.getElementById('repEngNum').value;
       <?php

       }

       function edRepBodyNumJSKeyUp($sender, $params)
       {

       ?>
       //Add your javascript code here
       window.opener.document.getElementById('edBodyNum').value = document.getElementById('edRepBodyNum').value;
       <?php

       }

}

global $application;

global $Replace_Engine;

//Creates the form
$Replace_Engine=new Replace_Engine($application);

//Read from resource file
$Replace_Engine->loadResource(__FILE__);

//Shows the form
$Replace_Engine->show();

?>